﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using Model.Interfaces;
using ViewModel.Interfaces;

[assembly: InternalsVisibleTo("Tests")]
namespace ViewModel
{
    public class MainViewModel
    {
        //this will be used in Release
        public MainViewModel()
        {
            //right now ViewModelObjectFactory is not implemented on purpose, so using it will and it should throw NotImplementedException
           // _factory = new ViewModelObjectFactory();
           // _scrumPro = new ScrumPro();
            InitiatePrivateMembers();
        }

        //this is for Testing and Debugging only
        internal MainViewModel(IViewModelObjectFactory factory, IScrumPro scrumPro)
        {
            _factory = factory;
            _scrumPro = scrumPro;
            InitiatePrivateMembers();
        }

        void LoginManagerLoginSuccess(object sender, ILoggedInEventArgs e)
        {
            _CurrentViewModel = _ProjectsViewModel;
            UserLoggedIn = e.User;
        }

        private void InitiatePrivateMembers()
        {
            _LogInViewModel = _factory.CreateLoginViewModel();
            _ProjectsViewModel = _factory.CreateProjectsViewModel();
            _CurrentViewModel = _LogInViewModel;
            _scrumPro.LoginManager.LoginSuccess += LoginManagerLoginSuccess;
        }

        private IViewModelObjectFactory _factory;
        private IViewModelBase _CurrentViewModel;
        private IProjectsViewModel _ProjectsViewModel;
        private ILoginViewModel _LogInViewModel;
        private IScrumPro _scrumPro;

        public IViewModelBase CurrentViewModel 
        { 
            get { return _CurrentViewModel; }
            set { _CurrentViewModel = value; }
        }

        public IUser UserLoggedIn { get; set; }
    }
}
